#!/bin/sh

. /etc/profile

LOCKDIR="/var/lock/"
LOCKFILE="boblight4j-client-X11"

case "$1" in
  hibernate|suspend)
  	PID=`ps aux | grep boblight4j-client-X11 | grep -v grep | awk '{print $1}'`
    if [ -n "${PID+x}" ];then
      progress "Shutting down boblight4j-client-X11 for suspending..."
      mkdir -p "$LOCKDIR"
      touch "$LOCKDIR/$LOCKFILE"
      kill $PID
    fi
    ;;

  thaw|resume)
    if [ -f "$LOCKDIR/$LOCKFILE" ];then
      progress "Restarting boblight4j-client-X11 for wake-up ..."
      boblight4j-client-X11.service
      rm -rf "$LOCKDIR/$LOCKFILE"
    fi
    ;;

  *) exit $NA
    ;;
esac
